import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:date_format/date_format.dart';
import 'action.dart';
import 'state.dart';
import '../../../app_files.dart';

Widget buildView(
    PhotoUploadViewState state, Dispatch dispatch, ViewService viewService) {

  Widget _infoWidget() {
    if (state.type == 0) {
      CheckListItemModel model = state.info;
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            '时间：${formatDate(
              DateTime.now(),
              [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn],
            )}',
            style: TextThemeConfig.Font14WithMainColor,
          ),
          Padding(padding: EdgeInsets.only(top: 5)),
          Text(
            '经纬度：${state.data == null ? '' : '${state.data.latitude};${state.data.longitude}'}',
            style: TextThemeConfig.Font14WithMainColor,
          ),
          Padding(padding: EdgeInsets.only(top: 5)),
          Text(
            '安检员：${GlobalStore.store.getState().userInfo.nickname}',
            style: TextThemeConfig.Font14WithMainColor,
          ),
          Padding(padding: EdgeInsets.only(top: 5)),
          Text(
            '客户姓名：${model.userName}',
            style: TextThemeConfig.Font14WithMainColor,
          ),
          Padding(padding: EdgeInsets.only(top: 5)),
          Text(
            '客户地址：${model.userAddress}',
            style: TextThemeConfig.Font14WithMainColor,
          ),
        ],
      );
    }
    else if (state.type == 1) {
      PatrolOrderItemModel model = state.info;
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            '时间：${formatDate(
              DateTime.now(),
              [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn],
            )}',
            style: TextThemeConfig.Font14WithMainColor,
          ),
          Padding(padding: EdgeInsets.only(top: 5)),
          Text(
            '经纬度：${state.data == null ? '' : '${state.data.latitude};${state.data.longitude}'}',
            style: TextThemeConfig.Font14WithMainColor,
          ),
          Padding(padding: EdgeInsets.only(top: 5)),
          Text(
            '巡线员：${GlobalStore.store.getState().userInfo.nickname}',
            style: TextThemeConfig.Font14WithMainColor,
          ),
          Padding(padding: EdgeInsets.only(top: 5)),
          Text(
            '管点名称：${model.pointName}',
            style: TextThemeConfig.Font14WithMainColor,
          ),
          Padding(padding: EdgeInsets.only(top: 5)),
          Text(
            '管点地址：${model.pointAddress}',
            style: TextThemeConfig.Font14WithMainColor,
          ),
        ],
      );
    }
    else {
      {
        FixListItemModel model = state.info;
        return Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              '时间：${formatDate(
                DateTime.now(),
                [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn],
              )}',
              style: TextThemeConfig.Font14WithMainColor,
            ),
            Padding(padding: EdgeInsets.only(top: 5)),
            Text(
              '经纬度：${state.data == null ? '' : '${state.data.latitude};${state.data.longitude}'}',
              style: TextThemeConfig.Font14WithMainColor,
            ),
            Padding(padding: EdgeInsets.only(top: 5)),
            Text(
              '维修员：${GlobalStore.store.getState().userInfo.nickname}',
              style: TextThemeConfig.Font14WithMainColor,
            ),
            Padding(padding: EdgeInsets.only(top: 5)),
            Text(
              '客户姓名：${model.userName}',
              style: TextThemeConfig.Font14WithMainColor,
            ),
            Padding(padding: EdgeInsets.only(top: 5)),
            Text(
              '客户地址：${model.address}',
              style: TextThemeConfig.Font14WithMainColor,
            ),
          ],
        );
      }
    }
  }

  return Scaffold(
    appBar: myAppBar(viewService.context, title: '预览图片'),
    backgroundColor: Colors.white,
    body: Column(
      children: [
        Container(
          margin: EdgeInsets.only(top: 26, left: 16, right: 16),
          constraints: BoxConstraints(maxHeight: ScreenUtil.screenHeightDp - 260),
          width: double.infinity,
          child: RepaintBoundary(
            key: state.rootWidgetKey,
            child: Stack(
              children: [
                Container(
                  width: ScreenUtil.screenWidthDp,
                  child: Image.file(
                    state.selectImage,
                    fit: BoxFit.fitWidth,
                    key: GlobalKey(),
                  ),
                ),
                Positioned(
                  child: _infoWidget(),
                  bottom: 12,
                  left: 12,
                ),
              ],
            ),
          ),
        ),
        Container(
          margin: EdgeInsets.symmetric(horizontal: 15, vertical: 40),
          height: 50,
          decoration: BoxDecoration(
            color: ThemeConfig.mainColor,
            borderRadius: BorderRadius.all(Radius.circular(4)),
          ),
          child: InkWell(
            child: Align(
              child: Text(
                '保存',
                style: TextThemeConfig.Font16WithWhite,
              ),
            ),
            onTap: () => dispatch(PhotoUploadViewActionCreator.onSubmit()),
          ),
        ),
      ],
    ),
  );
}
